package com.demo.controller;


import com.demo.vo.Function;
import com.demo.vo.FuncVOSeacherInfo;
import com.demo.vo.User;
import com.demo.service.FuncVOService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.List;

@Controller
public class FuncVOController {

    @Autowired
    FuncVOService funcVOService;

    @RequestMapping("getFuncList")
    @ResponseBody
    public HashMap getFuncList(FuncVOSeacherInfo info){
        HashMap map=new HashMap();
        List<Function> funcList=funcVOService.getFuncList(info);
        int totalCount=funcVOService.getFuncCount(info);
        map.put("code",0);
        map.put("msg","");
        map.put("count",totalCount);
        map.put("data",funcList);
        return map;
    }

    @RequestMapping("addFunc")
    @ResponseBody
    public HashMap addFunc(Function function){
        HashMap map=new HashMap();
        int res=funcVOService.addFunc(function);
        if(res>0){
            map.put("code",0);
            map.put("msg","添加成功");
        }else{
            map.put("code",-1);
            map.put("code","添加失败");
        }
        return map;
    }

    @RequestMapping("deleteFunc")
    @ResponseBody
    public HashMap deleteMod(String funcId){
        HashMap map=new HashMap();
        int res=funcVOService.deleteFunc(funcId);
        if(res>0){
            map.put("code",0);
            map.put("msg","删除成功");
        }else{
            map.put("code",-1);
            map.put("code","删除失败");
        }
        return map;
    }

    @RequestMapping("updateFunc")
    @ResponseBody
    public HashMap updateMod(Function function){
        HashMap map=new HashMap();
        int res=funcVOService.updateFunc(function);
        if(res>0){
            map.put("code",0);
            map.put("msg","修改成功");
        }else{
            map.put("code",-1);
            map.put("code","修改失败");
        }
        return map;
    }


    @RequestMapping("getUserListByuserType")
    @ResponseBody
    public HashMap getUserListByuserType(String userType){
        HashMap map=new HashMap();
        List<User> userList=funcVOService.getUserListByuserType(userType);
        map.put("code",0);
        map.put("msg","");
        map.put("data",userList);
        map.put("count",0);
        return map;
    }
}
